home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_376 / aztecarp / sources.lzh / rstart.asm < prev    next >
Assembly Source File  |  1990-08-01  |  5KB  |  189 lines

  1. ;:ts=8
  2. ;
  3. ; Initial startup routine for Aztec 'C' and ARP using RESIDENT.
  4. ; NB: This should allow access to all Aztec Features, math, etc.
  5. ;     Could be made smaller if only for CLI, only for Workbench,
  6. ;     Could be made smaller if only this or that.
  7. ;
  8. ; Created 02-18-88 by -+=SDB+=- from arpcrt0.s
  9. ; Copyright (c) 1988 by Scott Ballantyne, may be freely
  10. ; used by Arp Supporters/users.
  11. ; Use at your own risk.
  12. ;
  13. ; NB: References to the ___fromdisk__ long have to be handled carefully,
  14. ;     since they are somewhat shizophrenic, sometimes referring to copied
  15. ;     data, sometimes not.  Note that they should fine for the C code without
  16. ;     special handling as long as small model is used.
  17. ;
  18. ; May 9, 1988:    Move OpenLibrary() call into _main() to fix WBench Bug.
  19. ;        Add AhOhNoARP() callout for better user interface.
  20. ;
  21. ; 10-Mar-90:    Put together from resgeta4.s & arprescrt0.s for
  22. ;        Aztec 5.0 release.
  23. ;
  24. ;        Note:    define ARPONLY to create startup code for Arp
  25. ;            tool, the default is standard Aztec startup code.
  26. ;            The reason for this is: Arp opens dos.library in
  27. ;            _main() while the standard Aztec startup code
  28. ;            opens it before entering _main().
  29. ;
  30.  
  31.         include "exec/types.i"
  32.         include "exec/execbase.i"
  33.         include "exec/memory.i"
  34.         include "exec/tasks.i"
  35.         include "exec/alerts.i"
  36.         include "libraries/arpbase.i"
  37.     include    "exec/execbase.i"
  38.  
  39. call    macro
  40.     xref    _LVO\1
  41.     jsr    _LVO\1(a6)
  42.     endm
  43.  
  44.         mc68881
  45.         entry   .begin
  46.         public  .begin
  47.         public  _geta4
  48.  
  49. *       If you need more or less stack, change the first number below
  50. *       For example, if your program only needs 4000 bytes of stack, the
  51. *       line below would read:
  52. *       RESIDENT 4000,__H2_end-__H1_org,loaded
  53. *
  54.  
  55. .begin
  56.         RESIDENT 10240,__H2_end-__H1_org,loaded
  57.         moveq.l #0,d7                   ; flag resident code
  58.         move.l  a4,a3                   ; copy base
  59.         add.l   #32766,a4               ; bias
  60.         bra.s   clonedata               ; and copy the data segment only
  61. loaded: moveq.l #-1,d7                  ; flag not resident (start if from disk)
  62.         far data
  63.         move.l  d7,___fromdisk__        ; needs to be set for _geta4
  64.         near data
  65.         bsr     _geta4
  66. isresident:
  67.         lea     __H1_end,a1
  68.         lea     __H2_org,a2
  69.         cmp.l   a1,a2                   ;check if BSS and DATA together
  70.         bne     normal                  ; this would actually be an error.
  71.         move.w  #((__H2_end-__H2_org)/4)-1,d1
  72.         bmi     normal
  73.         move.l  #0,d2
  74.  
  75. loop    move.l  d2,(a1)+                ;clear out memory
  76.         dbra    d1,loop
  77.         bra.s   normal
  78.  
  79. clonedata:
  80.         move.l  #((__H1_end-__H1_org)/4)-1,d1
  81.         bmi.s   normal
  82.         far     data
  83.         lea     __H1_end,a1
  84.         lea     __H2_org,a2
  85.         cmp.l   a1,a2
  86.         beq.s   1$
  87.         move.l  #500,d0                 ; error, must be same hunk, so scram
  88.         rts
  89.  
  90. 1$:     lea.l   __H1_org,a1             ; clone data and bss
  91.  
  92.         near    data
  93. 0$      move.l  (a1)+,(a3)+             ; a3 set to point to base
  94.         dbra    d1,0$
  95.  
  96. normal: move.l  sp,__savsp              ; save stack pointer
  97.         move.l  4,a6                    ; get Exec's library base pointer
  98.         move.l  a6,_SysBase             ; put where we can get it
  99.         movem.l d0/a0,-(sp)             ; save CLI command parameters
  100.  
  101.     move.w    AttnFlags(a6),d0
  102.     btst    #AFB_68881,d0           ;check for 68881 flag in AttnFlags
  103.         beq     1$                      ;skip if not
  104.         lea     2$,a5
  105.     call    Supervisor              ;do it in supervisor mode
  106.         bra     1$
  107.  
  108. 2$      clr.l   -(sp)
  109.         frestore (sp)+                  ;reset the ffp stuff
  110.         rte                             ;and return
  111.  
  112. 1$    IFND ARPONLY
  113.     lea    dos_name,a1        ;get name of dos library
  114.     moveq    #0,d0            ;any version
  115.     call    OpenLibrary        ;open the library
  116.     move.l    d0,_DOSBase        ;set it up
  117.     bne    3$            ;skip if okay
  118.  
  119.       move.l  #AG_OpenLib!AO_DOSLib,d7;AG_OpenLib | AO_DOSLib
  120.     call    Alert            ;Alert
  121.     bra    4$
  122.  
  123. 3$    jsr    __main            ;call the startup stuff
  124.     tst.l    _DOSBase        ;lib still open?
  125.     beq.s    4$            ;nope
  126.     move.l    _DOSBase,a1
  127.     move.l    4,a6
  128.     call    CloseLibrary        ;close it then
  129.  
  130. 4$    lea    8(sp),sp            ;pop args
  131.     rts                ;and return
  132.  
  133. dos_name:
  134.     dc.b    'dos.library',0
  135.     ENDC
  136.  
  137.     IFD ARPONLY
  138.         jsr     __main                  ;call the startup stuff
  139.         lea    8(sp),sp                ;pop args
  140.         rts                             ;and return
  141.     ENDC
  142.  
  143. _geta4:
  144.     far    data
  145.     movem.l    d0-d1/a0-a1/a6,-(sp)    ; max safety here...
  146.     tst.l    ___fromdisk__
  147.     bne.s    1$
  148.     move.l    4,a6
  149.     move.l    ThisTask(a6),a0
  150.     lea.l    TC_MEMENTRY(a0),a0
  151.     lea.l    PMEM(pc),a1
  152.     call    FindName
  153.     move.l    d0,a0
  154.     cmp.w    #2,pm_Num(a0)        ; check for data
  155.     bne.s    1$            ; resident, but no data allocated.
  156.     move.l    pm_Data(a0),a4        ; get data pointer
  157.     add.l    #32766,a4        ; bias 
  158.     bra.s    2$
  159. 1$    lea.l    __H1_org+32766,a4
  160. 2$    movem.l    (sp)+,d0-d1/a0-a1/a6
  161.     rts
  162.  
  163. PMEM    PMEM_NAME
  164.  
  165.         public  __main,__H0_org
  166.  
  167.         dseg
  168.         
  169.         public  _SysBase,_DOSBase,__savsp,___fromdisk__,___sloppy__
  170.         public  __H1_org,__H1_end,__H2_org,__H2_end
  171.  
  172.     near    data
  173.  
  174.     even
  175.  
  176. ___fromdisk__:
  177.     dc.l    0    ; default is resident
  178. ___sloppy__:
  179.  
  180.     ifnd ARPONLY
  181.     dc.l    0
  182.     endc
  183.  
  184.     ifd ARPONLY
  185.     dc.l    1
  186.     endc
  187.  
  188.     end
  189.